<?php
include("../../inc/global.inc");
include("islogin.php");
$id = intval($_GET['id']);
$type = intval($_GET['type']);
if(!$id) exit('参数错误');
$table = $type ? 'hot_pro' : 'product';
$urlname = $type ? '/hot' : '/Supply';
$sql="select * from  `".$table."`  where id=".$id." and p_sh=1 and member_id>0";
$row=$db->get_one($sql);
if(!$row){
 echo "<script>location='/err.html';</script>";
}
//print_r($row);
if($row['member_id'] == $per_row['id'])
{
	echo "<script>alert('请勿购买自己商品');location='".HTTP_REFERER."';</script>";exit;
}
$head['title']='申请产品款托管交易';
$memberinfo = $db->get_one('select * from member where id ='.$row['member_id']);
$array = array();
if(isset($_POST['submit']) && $_POST['submit'])
{
	$array = $_POST['info'];
	$array['pid']=$row['id'];
	$array['title']=$row['p_title'];
	$array['url']=$urlname.'/'.$row['id'].'.html';
	$array['inputtime']=time();
	$array['updatetime']=time();
	$array['ip']=ip();
	$array['userid']=$per_row['id'];
	$array['userid2']=$row['member_id'];
	$array['username']=$per_row['m_user'];
	$array['username2']=$memberinfo['m_user'];
	
	$true = $db->insert('sd_tuoguan', $array);
	if($true)
	{
		$_title="三帝贸易网提示:您有客户购买您的商品申请了三帝托管保支付交易，请您及时登陆三帝网您的会员后台查看交易信息。";
		$data['member_id'] = $memberinfo['id'];
		$data['m_subject'] = '您有一封新的托管保交易邮件';
		$data['m_web'] = SITE_URL.'member/tuoguan/shoukuan.php';
		$data['m_content'] = $_title;
		$data['m_name'] = $array['truename'];
		$data['m_tel'] = $array['tel'];
		$data['m_email'] = $array['email'];
		$data['m_qq'] = $array['qq'];
		sendmessage($data);
		sendtel($memberinfo['m_phone'],$_title);
		$content = str_replace(array("{$user}","{$title}","{$content}"),array($memberinfo['m_user'],'您有一封新的托管保交易邮件',$_title),$mailcontent);
		@sendmail($memberinfo['m_email'],"询价邮件来自三帝贸易网",$content);
		echo "<script>alert('托管成功');location='/member/tuoguan/guanli.php?fukuan=1';</script>";exit;
	}
	else
	{
		echo "<script>alert('托管失败，未知原因。请联系管理员');location='".HTTP_REFERER."';</script>";exit;
	}
}	
?>
<?php include("top.php");?>
<div class="con">
		   <div class="top5"><span>您当前位置：<a href="/help/">会员助手</a> &gt;&gt; 托管交易管理</span></div>
		   <?php include("left.php");?>
		   <div class="right">
		      <div class="y_5"></div>
		       <div class="con-tt"><span>申请产品款托管交易</span></div>
			   <div class="con-t1"><span> 请仔细填写托管交易信息：（以下是经买卖双方商定好的交易订单信息）</span></div>
			   <div class="con-t2"><form action="" method="post" onsubmit="return check();"><table width="100%" border="0" cellpadding="0" cellspacing="0" >
			         <tr>
		                <td  height="28" align="center" bgcolor="#EFF6FF">产品名称：</td>
		                <td colspan="2" bgcolor="#f9f9f9">&nbsp;<a href="<?php echo $urlname;?>/<?php echo $row['id'];?>.html" target="_blank"><?php echo $row['p_title'];?></a></td>
	                </tr>
	                 <tr>
	                 <tr>
		                <td  height="28" align="center" bgcolor="#EFF6FF">联系人：</td>
		                <td colspan="2" bgcolor="#f9f9f9"><input name="info[truename]" type="text" class="txt1" id="truename"/>  <span>*</span></td>
	                </tr>
	                 <tr>
		                <td height="30" bgcolor="#EFF6FF" align="center"> 联系电话：</td>
		                <td colspan="2" bgcolor="#f9f9f9"><input name="info[tel]" type="text"class="txt1" id="tel" />  <span>*</span></td>
	                </tr>
	                 <tr>
		                <td height="30" bgcolor="#EFF6FF" align="center">联系QQ：</td>
		                <td bgcolor="#f9f9f9"><input name="info[qq]" type="text" class="txt1"/></td>
	                	<td bgcolor="#f9f9f9" style="border-left:0px;">QQ或邮箱二选一</td>
                    </tr>
	                 <tr>
		                <td height="30" bgcolor="#EFF6FF" align="center">联系邮箱：</td>
		                <td colspan="2" bgcolor="#f9f9f9"><input name="info[email]" type="text"class="txt1" /></td>
	                </tr>
	                 <tr>
		                <td height="30" bgcolor="#EFF6FF" align="center">交易金额：</td>
		                <td colspan="2" bgcolor="#f9f9f9"><input name="info[price]" type="text" class="txt2" id="price"/>
	                     元 <span>*</span></td>
	                </tr>
	                <tr>
		               <td height="205" bgcolor="#EFF6FF" align="center">产品名称及交易详细信息：</td>
		               <td colspan="2" bgcolor="#f9f9f9">&nbsp;<textarea name="info[content]" class="txt3" cols="70" rows="15"></textarea><br/>&nbsp;<span>*</span>必须详细填写</td>
	                </tr>
	                 <tr>
		                <td height="35"  align="center" bgcolor="#EFF6FF">提示：</td>
		                <td colspan="2" bgcolor="#f9f9f9">&nbsp;托管费2%我们直接在交易款项中扣除，请买卖双方交易前协商支付托管费。</td>
	                </tr>
	                 <tr>
		                 <td height="30" align="center" bgcolor="#EFF6FF">托管交易内容和具体要求：</td>
		                 <td colspan="2" bgcolor="#f9f9f9">&nbsp;<input id="tongyi" type="checkbox" checked="checked"/><a href="/tuoguan/about.php" target="_blank">&nbsp;我同意三帝贸易网托管交易规则</a></td>
	                 </tr>
	                  <tr>
		                  <td height="35" bgcolor="#EFF6FF">&nbsp;</td>
		                  <td colspan="2" bgcolor="#f9f9f9">&nbsp;<input name="submit" type="submit" class="btn" id="submit" value="申请托管交易" /></td>
	                  </tr>
                 </table></form>
             </div>
		 </div>
		 <div class="cl"></div>
</div> 
<?php include("foot.php");?>
<script>
	function check()
	{
		if($('#truename').val()=='')
		{
			alert('请输入联系人');
			$('#truename').focus();
			return false;
		}
		if($('#tel').val()=='')
		{
			alert('请输入电话');
			$('#tel').focus();
			return false;
		}
		if($('#price').val()=='')
		{
			alert('请输入价格');
			$('#price').focus();
			return false;
		}
		if($("#tongyi").attr("checked")!='checked')
		{
			alert('请选择同意条款');
			$('#tongyi').focus();
			return false;
		}
	}
</script>
